package standard

import (
	"go-forth/pkg/forth"
	"strings"
)

func Search(vm forth.StackVM) {
	s2 := getString(vm)
	s1 := getString(vm)
	pos := strings.Index(s1, s2)
	if pos == -1 {
		vm.Push(s1)
		vm.Push(0)
		vm.Push(vFalse)
	} else {
		vm.Push(s1[pos:])
		vm.Push(pos)
		vm.Push(vTrue)
	}
}

func Compare(vm forth.StackVM) {
	s2 := getString(vm)
	s1 := getString(vm)
	if s1 == s2 {
		vm.Push(0)
	} else if s1 < s2 {
		vm.Push(-1)
	} else {
		vm.Push(1)
	}
}
